/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import POJO.NhanVienPoJo;
import java.sql.ResultSet;
import javax.swing.JOptionPane;

/**
 *
 * @author tran quoc thinh
 */
public class NhanVienDAO {
    public static ResultSet LayBangNhanVien()
    {
       MySQLDataAccessHelper helper =new MySQLDataAccessHelper();
       helper.Open();
       String sql="select * from nhanvien";
       ResultSet rs=helper.excecuteQuery(sql);       
       return rs;       
    }
     public static int SuaNhanVien(NhanVienPoJo nv)
    {
         MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
         helper.Open();
         String sql=String.format("UPDATE nhanvien SET TenNV='%s',DienThoai='%s',DiaChi='%s',NgaySinh='%s',"
                        +"QuyenHan='%d',UserName='%s',PassWord='%s' WHERE MaNV='%s'",nv.getTenNV(),nv.getDienThoai(),nv.getDiaChi(),nv.getNgaySinh(),nv.getQuyenHan(),nv.getUserName(),nv.getPassword(),nv.getMaNV());
         int n=helper.excecuteUpdate(sql);
         helper.Close();
         return n;
    }
     public static int ThemNhanVien(NhanVienPoJo nv)
    {
        MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
        helper.Open();
        String sql=String.format("INSERT INTO nhanvien (MaNV,TenNV,DienThoai,DiaChi,NgaySinh,QuyenHan,UserName,PassWord)"
                + "VALUES('%s','%s','%s','%s','%s','%d','%s','%s')",nv.getMaNV(),nv.getTenNV(),nv.getDienThoai(),nv.getDiaChi(),nv.getNgaySinh(),nv.getQuyenHan(),nv.getUserName(),nv.getPassword());
        int n=helper.excecuteUpdate(sql);
        helper.Close();
        return n;
    }
     
    public static int CapNhatNhanVien(NhanVienPoJo nv)
    {
         MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
         helper.Open();
         String sql= "UPDATE `chieuphimonline`.`nhanvien` SET `TenNV`='"+nv.getTenNV()+"', `DienThoai`='"+nv.getDienThoai()+"', `DiaChi`='"+nv.getDiaChi()+"', `NgaySinh`='"+nv.getNgaySinh()+"', `PassWord`='"+nv.getPassword()+"' WHERE `MaNV`='"+nv.getMaNV()+"';";
         int n=helper.excecuteUpdate(sql);
         helper.Close();
         return n;
    }
     public static int XoaNhanVien(String nv){
        
         MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
         helper.Open();
         String sql=String.format("DELETE FROM nhanvien WHERE MaNV='%s'",nv );
         int n=helper.excecuteUpdate(sql);
         helper.Close();
         return n;
    }
}
